import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter)

const homeChildrenPath = [
  {
    // 用户管理 以及路由
    path: '/home/userManagement',
    name: 'UserManagement',
    component: () => import('../views/home/userManagement/UserManagement.vue'),
    meta: {
      title: "用户",
    
      homeChildrenPath: true, // 标识 二级路由的标识 
    }
  },
  {
    // 菜单管理 以及路由
    path: '/home/menuManagement',
    name: 'MenuManagement',
    component: () => import('../views/home/menuManagement/MenuManagement.vue'),
    meta: {
      title: "菜单",
     
      homeChildrenPath: true, // 标识 二级路由的标识
    }
  },
  {
    // 角色管理 以及路由
    path: '/home/roleMenagement',
    name: 'RoleMenagement',
    component: () => import('../views/home/roleMenagement/RoleMenagement.vue'),
    meta: {
      title: "角色",
      
      homeChildrenPath: true, // 标识 二级路由的标识
    }
  },
  {
    // 菜单类型管理以及路由
    path: '/home/roleTypeMenagement',
    name: 'RoleTypeMenagement',
    component: () => import('../views/home/roleTypeMenagement/RoleTypeMenagement.vue'),
    meta: {
      title: "菜单类型",
  
      homeChildrenPath: true, // 标识 二级路由的标识
    }
  },
  {
    // 操作日志以及路由
    path: '/home/ULogMenagement',
    name: 'ULogMenagement',
    component: () => import('../views/home/ULogMenagement/ULogMenagement.vue'),
    meta: {
      title: "操作日志",
   
      homeChildrenPath: true, // 标识 二级路由的标识
    },
  },
  {
    path: "/home",
    redirect: '/home/userManagement',  // 重定向:重新指向其它path,会改变网址
  }
]

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: () => import('../views/Home.vue'),
    children: homeChildrenPath
  },
  {
    path: '/index',
    name: 'Index',
    component: () => import('../views/Index.vue'),
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/login/Login.vue'),
  },
  {
    path: "/",
    redirect: '/home',  // 重定向:重新指向其它path,会改变网址
  }
]

export const dynamic = [
  {
    // 权限管理路由
    path: '/home/administrationAuthority',
    name: 'AdministrationAuthority',
    component: () => import('../views/home/administrationAuthority/AdministrationAuthority.vue'),
    meta: {
      title: "管理权限",
 
      homeChildrenPath: true, // 标识 二级路由的标识
    },
  },
]



const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// console.log('out')
// if (window.localStorage.getItem("token")) {
//   dynamic.forEach(item => {
//     // homeChildrenPath.push(item)
//     console.log(666666666)
//     router.addRoute("Home",item)
//   })
// }

export default router
